// pages/recordDetail/recordDetail.js
const amapFile = require('../../utils/plug/amap-wx/amap-wx.js');
const QQMapWX = require('../../utils/plug/qqmap-wx-jssdk1.0/qqmap-wx-jssdk.min.js');

const wxMap = new QQMapWX({
    key: 'ITABZ-JIILK-VEPJ3-AICX3-YMWA5-YBFFB'
});

Page({

    /**
     * 页面的初始数据
     */
    data: {
        showInfo: {},
        selectData: [{
            "id": "10",
            "text": "会计类"
        }, {
            "id": "21",
            "text": "工程类"
        }],
        userInfo: '',
        address: '',

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        const _this = this;
        const evChannel = _this.getOpenerEventChannel();
        evChannel.on('acceptData_recordList', function (data) {
            if (data) {
                _this.setShowInfo(data);
            }
        })


        // _this.getUserInfo(); 
        _this.reverseGeocoder();

    },


    getUserInfo(e) {
        const _this = this; 
        let resData = e.detail.userInfo
        console.log(e)
        _this.setData({
            userInfo: resData
        })


        // wx.getUserInfo({
        //     success: function (res) {
        //         // console.log(res);
        //         // _this.data.userInfo = res.userInfo;

        //         _this.setData({
        //             userInfo: res.userInfo
        //         })
        //     },
        //     fail: function (err) {
                // _this.setData({
                //     userInfo: '名字报错了！'
                // })
        //     }
        // });
    },

    // getLocation() {
    //     const _this = this;
    //     let myAmapFun = new amapFile.AMapWX({key:'5b0f548f711abda0a8d6feffbc7ef54f'});
    //     myAmapFun.getRegeo({
    //         success:(res)=>{
    //             console.log(res,res[0].regeocodeData.formatted_address) 
    //             let _locInfo = res[0].regeocodeData.addressComponent; 

    //             _this.setData({
    //                 address: _locInfo.province + _locInfo.city + _locInfo.district + _locInfo.streetNumber.street
    //             });
    //         }
    //     })
    // },

    reverseGeocoder() {
        const _this = this


        wx.getLocation({
            type: 'wgs84',
            success(res) {
                // const _latitude = res.latitude
                // const _longitude = res.longitude
                // const speed = res.speed
                // const accuracy = res.accuracy 

                wxMap.reverseGeocoder({
                    location: {
                        // 你的经纬度
                        latitude: res.latitude,
                        longitude: res.longitude,
                    },
                    success: function (data) {
                        // console.log(data);
                        if (data.status == 0) {
                            _this.setData({
                                address: data.result.address
                            });
                        }
                    },
                    fail: function (err) {
                        _this.setData({
                            address: '地址报错了 - reverseGeocoder'
                        });
                    }
                });
            },
            fail: function (err) {
                _this.setData({
                    address: '地址报错了 - getLocation'
                });
            }
        })


    },

    setShowInfo(data) {
        const _this = this;

        _this.setData({
            showInfo: data
        })

        console.log(_this.data)

    },




    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },


})